//
//  CollectViewController.m
//  CivilianTravel
//
//  Created by xalo on 16/7/26.
//  Copyright © 2016年 许仕杰. All rights reserved.
//

#import "CollectViewController.h"
#import "CollectionDatailViewController.h"
#import "CoreDataManager.h"
#import "CollectionTableViewCell.h"
@interface CollectViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation CollectViewController

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"收藏";
    [self.tableView registerNib:[UINib nibWithNibName:@"CollectionTableViewCell" bundle:nil] forCellReuseIdentifier:@"table_cell"];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [[CoreDataManager defaultManager] selectAllCollectionModel].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"table_cell" forIndexPath:indexPath];
    NSArray *array = [[CoreDataManager defaultManager] selectAllCollectionModel];
    NSLog(@"+++++++++%@",array);
    cell.title.text = [array[indexPath.row] title];
    cell.name.text = [array[indexPath.row] name];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CollectionDatailViewController *collectionVC = [[CollectionDatailViewController alloc] initWithNibName:@"CollectionDatailViewController" bundle:nil];
    NSArray *array = [[CoreDataManager defaultManager] selectAllCollectionModel];
    collectionVC.html = [array[indexPath.row] html];
    [self.navigationController pushViewController:collectionVC animated:YES];
}



@end
